//
//  EventTableView.m
//  HypERLtrace
//
//  Created by Vladimir Sarpe on 12/08/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "EventTableView.h"

@implementation EventTableView

- (NSString*) lifeTime:(int)row andIdentifier:(NSString*)ident {
	NSString* process = [[self dataSource] tableView:self objectValueForTableColumn:[self tableColumnWithIdentifier:ident] row:row];
	return [[lifes objectForKey:process] objectForKey:@"lifetime"];
}

- (void) updateLifeTimes:(NSDictionary*)dict {
	lifes = dict;
}

- (void)mouseMoved:(NSEvent *)theEvent {
	NSString* lifetime;
	NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
	if (mouseLoc.y > 0 && mouseLoc.y < [self bounds].size.height) {
		int row = (int)(mouseLoc.y/22);
		int max_rows = [[self dataSource] numberOfRowsInTableView:self];

		if(row < max_rows) {
			NSTableColumn* column = [self tableColumnWithIdentifier:@"timestamp"];
			NSString* time = [[self dataSource] tableView:self objectValueForTableColumn:column row:row];
			[graphView notifyMouseOverTime:[time intValue]];
			int col = [self columnAtPoint:mouseLoc];
			if (col > -1 && col < [[self tableColumns] count]) {
				NSString* col_id = [[[self tableColumns] objectAtIndex:col] identifier];
				if ([col_id isEqualToString:@"process"] || [col_id isEqualToString:@"receiver"]) {
					lifetime = [self lifeTime:row andIdentifier:col_id];
					if (lifetime != @"" && lifetime != nil)  {		
						[graphView notifyMouseOverActor:lifetime];
					}
					else
						[graphView notifyMouseOverActor:@"0-0"];
				}
				else
					[graphView notifyMouseOverActor:@"0-0"];
			}
		}
	}
	else 
		[graphView notifyMouseOverActor:@"0-0"];

}

- (BOOL)acceptsFirstResponder{
	return YES;
}

@end
